package cn.charmaine.basic.base.controller;

import cn.charmaine.basic.base.service.ILoginService;
import cn.charmaine.basic.util.AjaxResult;
import cn.charmaine.org.domain.dto.SmsCodeParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private ILoginService loginService;

    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult verifyCode(@PathVariable("imageCodeKey") String key){
        try {
            String image = loginService.generateImage(key);
            return new AjaxResult().setResultObj(image);//用无参的表示成功
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.thisSuccess().setSuccess(false).setMessage("操作失败");
        }
    }

    /**
     * 发送短信验证码
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SmsCodeParam smsCodeParam){
        try {
            loginService.sendSmsCode(smsCodeParam);
            return new AjaxResult();//用无参的表示成功
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.thisSuccess().setSuccess(false).setMessage("服务器忙！");
        }
    }


}
